﻿Imports extranet.BC
Imports extranet.BE
Imports System.Collections.Generic
Imports MetodosComuns

Public Class Aux
    Private _idPost As Integer
    Private _criador As String
    Private _titulo As String
    Private _totalPostsUsuario As Integer
    Private _data As Date
    Private _avatar As String
    Private _mensagem As String

    Public Property IdPost() As Integer
        Get
            Return _idPost
        End Get
        Set(ByVal value As Integer)
            _idPost = value
        End Set
    End Property
    Public Property Criador() As String
        Get
            Return _criador
        End Get
        Set(ByVal value As String)
            _criador = value
        End Set
    End Property
    Public Property Titulo() As String
        Get
            Return _titulo
        End Get
        Set(ByVal value As String)
            _titulo = value
        End Set
    End Property
    Public Property TotalPostsUsuario() As Integer
        Get
            Return _totalPostsUsuario
        End Get
        Set(ByVal value As Integer)
            _totalPostsUsuario = value
        End Set
    End Property
    Public Property Data() As Date
        Get
            Return _data
        End Get
        Set(ByVal value As Date)
            _data = value
        End Set
    End Property
    Public Property Avatar() As String
        Get
            Return _avatar
        End Get
        Set(ByVal value As String)
            _avatar = value
        End Set
    End Property
    Public Property Mensagem() As String
        Get
            Return _mensagem
        End Get
        Set(ByVal value As String)
            _mensagem = value
        End Set
    End Property


End Class


Partial Class forum_topico
    Inherits System.Web.UI.Page
    Dim idtopico As String
    Dim lstBEPost As List(Of BEPost)
    Dim objBEPost As BEPost
    Dim lstAuxiliar As List(Of Aux)
    Dim lstAuxiliarGridV2 As New List(Of Aux)
    Dim dummyAux As Aux
    Dim objBETopico As BETopico
    Dim objBESubcategoria As BESubcategoria
    Dim objBECategoria As BEForum

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objBESeguranca As New BESeguranca
        Dim objBEUsuario As BEUsuario = Session("objBEUsuario")

        If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
        Session("strTela") = MetodosComuns.GetCurrentPageName()
        If Not IsPostBack Then          ' SEGURANÇA
            objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
            If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
            Session("objBESeguranca") = objBESeguranca
        Else
            objBESeguranca = Session("objBESeguranca")
        End If

        Dim totPostsUsuario As Integer
        Dim i As Integer
        If Not IsPostBack Then
            idtopico = Request.QueryString("id")

            objBETopico = New BETopico
            objBESubcategoria = New BESubcategoria
            objBECategoria = New BEForum
            objBETopico = BCForum.SelecionaTopico(Convert.ToInt32(idtopico))
            objBESubcategoria = BCForum.SelecionaSubcategoria(objBETopico.IdSubcategoria.ToString)
            objBECategoria = BCForum.SelecionaCategoria(objBESubcategoria.IdCategoria.ToString)
            lblCaminho.Text = objBECategoria.Nome & " >> " & objBESubcategoria.Nome & " >> " & objBETopico.Titulo
            lblTituloTopico.Text = objBETopico.Titulo

            If Not objBESeguranca.Escrita Then 'Caso não seja administrador...
                GridView1.Columns(1).Visible = False
            End If

            objBEPost = New BEPost
            objBEPost.MensagemPost = New BEMensagem
            dummyAux = New Aux
            lstAuxiliar = New List(Of Aux)

            BCForum.IncVisualizacoes(idtopico)

            lstBEPost = BCForum.ListarPosts(0, idtopico) 'Pego a mensagem do topico correspondente
            objBEPost = lstBEPost(0)
            dummyAux.Avatar = "..\imagens\avatar\" & objBEPost.ImgAvatar
            dummyAux.Criador = objBEPost.MensagemPost.Remetente
            dummyAux.Mensagem = objBEPost.MensagemPost.Mensagem
            dummyAux.Data = objBEPost.MensagemPost.Data
            dummyAux.Titulo = objBEPost.TituloTopico
            dummyAux.TotalPostsUsuario = BCForum.ContaPostsUsuario(objBEPost.MensagemPost.Remetente)
            lstAuxiliarGridV2.Add(dummyAux)
            GridView2.DataSource = lstAuxiliarGridV2
            GridView2.DataBind()

            lstBEPost = BCForum.ListarPosts(1, idtopico)
            For i = 0 To lstBEPost.Count - 1
                dummyAux = New Aux
                totPostsUsuario = New Integer
                dummyAux.IdPost = lstBEPost(i).Id
                dummyAux.Avatar = "..\imagens\avatar\" & lstBEPost(i).ImgAvatar
                dummyAux.Criador = lstBEPost(i).MensagemPost.Remetente
                totPostsUsuario = BCForum.ContaPostsUsuario(dummyAux.Criador)
                dummyAux.Mensagem = lstBEPost(i).MensagemPost.Mensagem
                dummyAux.Data = lstBEPost(i).MensagemPost.Data
                dummyAux.Titulo = lstBEPost(i).TituloTopico
                dummyAux.TotalPostsUsuario = totPostsUsuario
                lstAuxiliar.Add(dummyAux)
            Next
            GridView1.DataSource = lstAuxiliar
            GridView1.DataBind()
        End If
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim strId As String
        Dim objBETopico As New BETopico
        strId = Request.QueryString("id")
        objBETopico = BCForum.SelecionaTopico(strId)

        Response.Redirect("subcategoria.aspx?id=" & objBETopico.IdSubcategoria)
    End Sub

    Protected Sub lnkBtnAddTopico_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnAddTopico.Click
        Response.Redirect("novo_post.aspx?id=" & Request.QueryString("id"))
    End Sub
End Class
